package br.com.fsa.aplication.Util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.hibernate.HibernateException;

import br.com.fsa.aplication.Exception.ConectionException;




public class HibernateListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		try
		{
			HibernateUtil.getSession().close();
			//HibernateUtil.getSessionFactory2().close();
		}
		catch (HibernateException e)
		{
			Util.gravaLog(e.getMessage());	
			
		}
		catch (ConectionException e)
		{
			Util.gravaLog(e.getMessage());
		}
		
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		
		try
		{
			HibernateUtil.getSession();
			//HibernateUtil.getSessionFactory2();		
		}
		catch (HibernateException e)
		{
			Util.gravaLog(e.getMessage());	
		}
		catch (ConectionException e)
		{
			Util.gravaLog(e.getMessage());
		}
	}	
}
